package com.big.user.biz.service.impl;

import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.big.common.core.util.ConvertUtil;
import com.big.common.mybatis.base.service.impl.BaseServiceImpl;
import com.big.user.api.domain.dto.SysUserDTO;
import com.big.user.biz.domain.entity.SysUser;
import com.big.user.biz.service.SysUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 *
 * </p>
 *
 * @author 山归岿
 * @create 2025-06-21-19:13
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class SysUserServiceImpl extends BaseServiceImpl<SysUserDTO, SysUser> implements SysUserService {
    @Override
    public SysUserDTO getOneDTO(SysUserDTO userDTO) {

        // 如果这三个查询条件都没有的话返回空
        if (ObjectUtil.isEmpty(userDTO.getUsername())
                && ObjectUtil.isEmpty(userDTO.getMobile())
                && ObjectUtil.isEmpty(userDTO.getEmail()) && ObjectUtil.isEmpty(userDTO.getId())) {
            return null;
        }
        LambdaQueryWrapper<SysUser> eq = new LambdaQueryWrapper<SysUser>()
                .eq(CharSequenceUtil.isNotBlank(userDTO.getUsername()), SysUser::getUsername, userDTO.getUsername())
                .eq(CharSequenceUtil.isNotBlank(userDTO.getMobile()), SysUser::getMobile, userDTO.getMobile())
                .eq(CharSequenceUtil.isNotBlank(userDTO.getEmail()), SysUser::getEmail, userDTO.getEmail())
                .eq(ObjectUtil.isNotEmpty(userDTO.getId()), SysUser::getId, userDTO.getId());
        SysUser user = this.getOne(eq);
        return ConvertUtil.convert(user, SysUserDTO.class);
    }
}
